﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PostSharp.Laos;
using Yatagan.Interfaces;

namespace Yatagan.BaseAspects
{
    public abstract class ExceptionAspect : OnExceptionAspect
    {
        public Type Exception { get; set; }
        public string Message { get; set; }

        public ExceptionAspect(Type exception, string message)
        {
            Exception = exception;
            Message = message;
        }

        public override void OnException(PostSharp.Laos.MethodExecutionEventArgs eventArgs)
        {
            if (Exception.IsAssignableFrom(eventArgs.Exception.GetType()))
            {
                WriteLog();
            }
        }

        protected abstract void WriteLog();
    }
}
